﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DataAccess;
using Model.EntityModel;

namespace Project
{
    /// <summary>
    /// Interaction logic for ViewCitationsContent.xaml
    /// </summary>
    public partial class ViewCitationsContent : UserControl
    {
        Citation citation = new Citation();
        List<Citation> citations = new List<Citation>();
        public ViewCitationsContent(long idComplaint)
        {
            InitializeComponent();
            UIWindowManager.SetWindowTitle(this, "Brigada De Protección a la Familia - Ver Citaciones");
            BtnUpdate.IsEnabled = false;
            BtnView.IsEnabled = false;
            citations= CitationDataAccess.GetCitationsByComplaint(idComplaint);
            List<DateTime> dates=new List<DateTime>();
            if (citations.Count == 0)
                LblError.Content = "No existen citaciones registradas";
            foreach (Citation c in citations)
            {
                dates.Add((DateTime)c.CitationDate);
            }
            listBox1.DataContext = dates;
            Binding binding = new Binding();
            listBox1.SetBinding(ListBox.ItemsSourceProperty, binding);
            LblIdComplaint.Content = "Citaciones de la denuncia " + idComplaint.ToString()+" :";
            if (UserControllerAndDataAccess.IsDirectorLogged)
                BtnUpdate.Visibility=Visibility.Hidden;
        }

       

        private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int i=listBox1.SelectedIndex;
            citation = citations[i];
            BtnUpdate.IsEnabled = true;
            BtnView.IsEnabled = true;
        }

        private void BtnView_Click(object sender, RoutedEventArgs e)
        {
            if (listBox1.SelectedIndex != -1)
            {

                Content.Children.Clear();
                ViewCitation n = new ViewCitation(Convert.ToInt64(citation.IdComplaint), citation.Id);
                Content.Children.Add(n);
            }
            else
            {
                MessageBox.Show("Seleccione un elemento", "Advertencia", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }

        private void BtnUpdate_Click(object sender, RoutedEventArgs e)
        {
            if (listBox1.SelectedIndex != -1)
            {
                
                Content.Children.Clear();
                Content.Children.Add(new UpdateCitation(Convert.ToInt64(citation.IdComplaint), Convert.ToInt64(citation.Id)));
            }
            else
                MessageBox.Show("Seleccione un elemento", "Advertencia", MessageBoxButton.OK, MessageBoxImage.Warning);
        }
    }
}
